package Three_ZhuChangShuang.service;

import Three_ZhuChangShuang.entity.Adenovirus;
import Three_ZhuChangShuang.entity.Inactivated;
import Three_ZhuChangShuang.entity.Person;
import Three_ZhuChangShuang.menu.Menu;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @Author zhu
 * @Date 2021/3/24 14:49
 * @ClassNmae UserServices
 * @Description 用户登录成功过后的功能
 */
public class UserServices {

    //用来记录当前登录的用户
    private int count;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Scanner scanner = new Scanner(System.in);
    Menu menu;
    Adenovirus adenovirus ;
    Inactivated inactivated ;
    Person[] persons;

    public Person[] getPersons() {
        return persons;
    }

    public void setPersons(Person[] persons) {
        this.persons = persons;
    }


    public Adenovirus getAdenovirus() {
        return adenovirus;
    }

    public void setAdenovirus(Adenovirus adenovirus) {
        this.adenovirus = adenovirus;
    }

    public Inactivated getInactivated() {
        return inactivated;
    }

    public void setInactivated(Inactivated inactivated) {
        this.inactivated = inactivated;
    }

    public Menu getMenu() {
        return menu;
    }

    public void setMenu(Menu menu) {
        this.menu = menu;
    }




    /**
     * @Author zhu
     * @Description 用户 灭活疫苗预约   Inactivated vaccine appointment
     * @Date 2021/3/23
     * @return void
     */
    public void iVaccineApp(){
        //将当前登录用户记录在count当中
        count = menu.getCount();
        if (menu.getPersons()[count].getSpecies()==0)
        {
            System.out.println("请输入预约日期：yyyy-mm-dd 格式");
            String str = scanner.next();
            try {
                Date time = sdf.parse(str);
            } catch (ParseException e) {
                // e.printStackTrace();
                System.out.println("输入的日期有误");
                return;
            }
            persons[count].setaTime(str);  //预约时间赋值过去
            persons[count].setStatus(0);   //接种状态改为未接种
            persons[count].setSpecies(1);  //传入1，表示预约的是灭活疫苗
            System.out.println("预约成功!");

            inactivated.information();
        }else if (persons[count].getSpecies()==1 || persons[count].getSpecies()==2){
            System.out.println("用户"+persons[count].getName()+"你已经预约了--" +
                    ((persons[count].getSpecies()==1)?"灭活疫苗!":"腺病毒疫苗!"));
        }
    }

    /**
     * @Author zhu
     * @Description 用户腺病毒疫苗预约
     * @Date 2021/3/23
     * @return void
     */
    public void  aVaccineApp(){
        count = menu.getCount();
        if (persons[count].getSpecies()==0){
            System.out.println("请输入预约日期：yyyy-mm-dd 格式");
            String str = scanner.next();
            try {
                Date time = sdf.parse(str);
            } catch (ParseException e) {
                // e.printStackTrace();
                System.out.println("输入的日期有误");
                return;
            }
            persons[count].setaTime(str);
            persons[count].setStatus(0);
            persons[count].setSpecies(2);
            System.out.println("预约成功！");
            adenovirus.information();
        }else if (persons[count].getSpecies()==1 || persons[count].getSpecies()==2){
            System.out.println("用户"+persons[count].getName()+"你已经预约了--"+
                    ((persons[count].getSpecies()==1)?"灭活疫苗!":"腺病毒疫苗!。"));
        }
    }

    /**
     * @Author zhu
     * @Description 用户修改联系方式
     * @Date 2021/3/23
     * @return void
     */
    public void modifyNumber(){
        count = menu.getCount();
        System.out.println("用户"+persons[count].getName()+"你将要修改你的预留电话号码！");
        System.out.println("你当前的预留电话号码是："+persons[count].getNumber());
        System.out.println("请输入你修改后的新号码：");
        String number = scanner.next();
        persons[count].setNumber(number);
        System.out.println("用户"+persons[count].getName()+"你的电话号码修改成功！"+"新号码为："+persons[count].getNumber());
    }

    /**
     * @Author zhu
     * @Description 用户修改登录密码
     * @Date 2021/3/23
     * @return
     */
    public void modifyPassword(){
        count = menu.getCount();
        boolean flag = false;
        System.out.println("用户"+persons[count].getName()+"你将要修改你的登录账户的密码！");
        while (!flag){
            System.out.println("请输入账户你的原密码：");
            String oldstr = scanner.next();
            if (persons[count].getPwd().equals(oldstr)){
                System.out.println("原密码校验正确");
                System.out.println("请输入修改后的密码：");
                persons[count].setPwd(scanner.next());
                flag=true;
                System.out.println("用户"+persons[count].getName()+"你的密码修改成功！"+"新密码为："+persons[count].getPwd());
            }else{
                System.out.println("原密码错误！");
            }
        }
    }
}


